﻿<extend name="Base/common" />

<block name="header">
<header>
<div class="container text-center">
    <h2>用户登录</h2>
</div>
</header>
</block>

<block name="body">
<section>

    <div class="row col-md-5 center-block">
    
        <div class="col-md-12 ">
        
            <form id="login-form" class="form-horizontal " action="__SELF__" method="post">
        
              <div class="form-group">
                  <label class=" form-label" for="inputEmail">用户名</label>
                      <input type="text" id="inputEmail" class="form-control input-lg " placeholder="请输入用户名"  errormsg="请填写1-16位用户名" nullmsg="请填写用户名" datatype="*1-16" value="" name="username">
              </div>
              
              <div class="form-group">
                  <label class="form-label" for="inputPassword">密码</label>
                      <input type="password" id="inputPassword"  class="form-control input-lg" placeholder="请输入密码"  errormsg="密码为6-20位" nullmsg="请填写密码" datatype="*6-20" name="password">
              </div> 
              
              <div class="form-group">
                <label class="form-label" for="inputVerify">验证码</label>
                      <input type="text" id="inputVerify" class="form-control input-lg" placeholder="请输入验证码"  errormsg="请填写5位验证码" nullmsg="请填写验证码" datatype="*5-5" name="verify">
              </div>
              
              <div class="form-group">
                      <img class="verifyimg reloadverify verify-img" alt="点击切换" src="{:U('verify')}" style="cursor:pointer;">
              </div>
                  
              <div class="form-group">
               <button type="submit" class="btn btn-default btn-lg col-md-3 col-xs-12" >登 陆</button>
              </div>
               
            </form>  
                
        </div>    
    
    </div>
    
</section>

</block>

<block name="side"> </block>
<block name="script">
	<script type="text/javascript">

    	$(document)
	    	.ajaxStart(function(){
	    		$("button:submit").attr("disabled", true);
	    	})
	    	.ajaxStop(function(){
	    		$("button:submit").attr("disabled", false);
	    	});


    	$("#login-form").submit(function(){
    		var self = $(this);
    		$.post(self.attr("action"), self.serialize(), success, "json");
    		return false;

    		function success(data){
    			if(data.status){
					$.zui.messager.success('登录成功',{placement:'center'});
					setTimeout(function(){window.location.href = data.url;},1000);
    			} else {
					$.zui.messager.warning(data.info,{placement:'center'});
    				//刷新验证码
    				$(".reloadverify").click();
    			}
    		}
    	});

		$(function(){
			var verifyimg = $(".verifyimg").attr("src");
            $(".reloadverify").click(function(){
                if( verifyimg.indexOf('?')>0){
                    $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
                }else{
                    $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
            });
		});

	</script>
</block>
